package uestc.lj.midPromotion.dfs;

/**
 * @Author:Crazlee
 * @Date:2021/12/6
 */
public class Code13_LongestNoRepeatSubstring {
	public static int maxUnique(String str) {
		if (str == null || "".equals(str)) {
			return 0;
		}
		char[] chars = str.toCharArray();
		// 代替哈希表，0..255是字符编码
		int[] map = new int[256];

		for (int i = 0; i < 256; i++) {
			map[i] = -1;
		}

		int len = 0;
		int pre = -1;
		int cur = 0;
		for (int i = 0; i < chars.length; i++) {
			pre = Math.max(pre, map[chars[i]]);
			cur = i - pre;
			len = Math.max(len, cur);
			map[chars[i]] = i;
		}
		return len;
	}
}
